package com.aaa.service.Impl;

import com.aaa.entity.LeadingUsers;
import com.aaa.mapper.LeadingMapper;
import com.aaa.service.LeadingUsersService;
import com.aaa.util.DefaultMsg;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用户管理service接口实现类
 */
@Service
@Transactional
public class LeadingUsersServiceImpl extends ServiceImpl<LeadingMapper, LeadingUsers> implements LeadingUsersService {

    @Resource
    private LeadingMapper leadingMapper;

    /**
     * 查询所有前台用户
     * @return
     */
    @Override
    public List<LeadingUsers> listAll(String keyword) {
        return leadingMapper.listAll(keyword);
    }

    /**
     * 删除前台用户
     * @param lid
     * @return
     */
    @Override
    public DefaultMsg delete(Integer lid) {
        DefaultMsg defaultMsg=new DefaultMsg();
        Integer delete = leadingMapper.delete(lid);
        if (delete==0){
            defaultMsg.setSuccess(0);
            defaultMsg.setMsg("删除失败");
        }
        return defaultMsg;
    }

    /**
     * 重置密码
     * @param leadingUsers
     * @return
     */
    @Override
    public DefaultMsg resetPasswords(LeadingUsers leadingUsers) {
        DefaultMsg defaultMsg = new DefaultMsg();
        Integer count = null;

        if(leadingUsers.getLid()!=null){
            count=  leadingMapper.resetPasswords(leadingUsers);
        }
        if (count==0){
            defaultMsg.setMsg("重置失败");
            defaultMsg.setSuccess(0);
        }
        return defaultMsg;
    }

    /**
     * 启用前台用户
     * @param leadingUsers
     * @return
     */
    @Override
    public Integer updateQi(LeadingUsers leadingUsers) {
        return leadingMapper.updateQi(leadingUsers);
    }

    /**
     * 禁用前台用户
     * @param leadingUsers
     * @return
     */
    @Override
    public Integer updateJin(LeadingUsers leadingUsers) {
        return leadingMapper.updateJin(leadingUsers);
    }
}
